home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 5 / Skunkware 5.iso / src / Tools / vg-2.03 / video / gamma.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-05-03  |  1.7 KB  |  86 lines

  1. /*
  2.  * Copyright (C) 1990-1992 by Michael Davidson.
  3.  * All rights reserved.
  4.  *
  5.  * Permission to use, copy, modify, and distribute this software
  6.  * and its documentation for any purpose and without fee is hereby
  7.  * granted, provided that the above copyright notice appear in all
  8.  * copies and that both that copyright notice and this permission
  9.  * notice appear in supporting documentation.
  10.  *
  11.  * This software is provided "as is" without express or implied warranty.
  12.  */
  13.  
  14. unsigned char    RGB8Lookup[3][256];
  15.  
  16. unsigned char    RGB32Bits[3]        = {  8,  8,  8 };
  17. unsigned char    RGB32Shift[3]        = { 16,  8,  0 };
  18. unsigned long    RGB32Lookup[3][256];
  19.  
  20. void
  21. gammaLookupInit(
  22.     long        gamma,
  23.     unsigned char    *lookup
  24.     )
  25. {
  26.     extern long        GammaLog10[256][2];
  27.  
  28.     long    log_d;
  29.     long    log_v;
  30.     int        i;
  31.     int        j;
  32.  
  33.  
  34.     log_d = (long)GammaLog10[255][0] * (gamma - 100);
  35.  
  36.     lookup[0]    = 0;
  37.     j        = 0;
  38.  
  39.     for (i = 1; i < 255; i++)
  40.     {
  41.     log_v    = (GammaLog10[i][0] * gamma) - log_d;
  42.     log_v    = (log_v + 50) / 100;
  43.     while (log_v > GammaLog10[j][1] && j < 255)
  44.         j++;
  45.  
  46.     lookup[i] = j;
  47.     }
  48.  
  49.     lookup[255] = 255;
  50. }
  51.  
  52. void
  53. vidSetGamma(
  54.     long    RedGamma,
  55.     long    GreenGamma,
  56.     long    BlueGamma
  57.     )
  58. {
  59.     register unsigned char    *lookup8;
  60.     register unsigned long    *lookup32;
  61.     register unsigned long    l;
  62.     int                i, j;
  63.     int                bits, shift;
  64.     long    gamma[3];
  65.  
  66.     gamma[0]    = RedGamma;
  67.     gamma[1]    = BlueGamma;
  68.     gamma[2]    = GreenGamma;
  69.  
  70.     for (i = 0; i < 3; i++)
  71.     {
  72.     lookup8    = RGB8Lookup[i];
  73.     lookup32= RGB32Lookup[i];
  74.  
  75.     gammaLookupInit(gamma[i], lookup8);
  76.     bits    = 8 - RGB32Bits[i];
  77.     shift    = RGB32Shift[i];
  78.  
  79.     for (j = 0; j < 256; j++)
  80.     {
  81.         l        = lookup8[j] >> bits;
  82.         lookup32[j] = l << shift;
  83.     }
  84.     }
  85. }
  86.